package com.vegetable.modules.service.inbound.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.modules.entity.finance.PaymentTeamDetail;
import com.vegetable.modules.entity.inbound.PackDeliveryTeam;
import com.vegetable.modules.mapper.inbound.PackDeliveryTeamMapper;
import com.vegetable.modules.service.inbound.IPackDeliveryTeamService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 加工打包 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-21
 */
@Slf4j
@Service
@AllArgsConstructor
public class PackDeliveryTeamServiceImpl extends ServiceImpl<PackDeliveryTeamMapper, PackDeliveryTeam> implements IPackDeliveryTeamService {
    @Override
    public void add(List<PackDeliveryTeam> po) {
        // 删除现在的
        deleteByDeliverId(po.get(0).getDeliveryId());
        // 批量保存
        saveBatch(po);
    }

    @Override
    public List<PackDeliveryTeam> selectByDeliveryId(Long deliveryId) {
        QueryWrapper<PackDeliveryTeam> wrapper = new QueryWrapper<>();
        wrapper.eq("delivery_id", deliveryId);
        return baseMapper.selectList(wrapper);
    }

    public int deleteByDeliverId(Long deliveryId){
        QueryWrapper<PackDeliveryTeam> wrapper = new QueryWrapper<>();
        wrapper.eq("delivery_id", deliveryId);
        return baseMapper.delete(wrapper);
    }
    @Override
    public boolean packFinishPay(List<PaymentTeamDetail> pos){
        List<PackDeliveryTeam> updaters = new ArrayList<>();
        for(PaymentTeamDetail po : pos){
            PackDeliveryTeam updater = new PackDeliveryTeam();
            updater.setId(po.getId());
            updater.setMoney(po.getMoney());
            updater.setIsPayFinish(1);
            updaters.add(updater);
        }
        return updateBatchById(updaters);
    }
}
